package com.huluobo.a2111douyindemo.startLive;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.huluobo.mvvm_base.mvvm.base.viewmodel.BaseViewModel;
import com.huluobo.mvvm_base.mvvm.bean.PushBeanResult;
import com.huluobo.mvvm_base.mvvm.bean.StopPushBeanResult;
import com.huluobo.mvvm_base.mvvm.net.Const;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LC on 2024/3/11.
 */
public class StartLiveViewModel extends BaseViewModel<StartLiveRepo> {

    MutableLiveData<PushBeanResult> startPushSuccess = new MutableLiveData<>();

    MutableLiveData<String> startPushFailed = new MutableLiveData<>();

    MutableLiveData<StopPushBeanResult> stopPushSuccess = new MutableLiveData<>();

    MutableLiveData<String> stopPushFailed = new MutableLiveData<>();

    public void startPush(String address, String caption) {
        Map<String, String> map = new HashMap<>();
        map.put(Const.PARAM_ADDRESS, address);
        map.put(Const.PARAM_CAPTION, caption);

        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.MEDIA_PARSE), json);
        repo.startPush(body, startPushSuccess, startPushFailed);
    }

    public void stopPush() {
        repo.stopPush(stopPushSuccess, stopPushFailed);
    }

    public StartLiveViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    protected StartLiveRepo createRepo() {
        return new StartLiveRepo();
    }
}
